package jlisp.ui.composite;

import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.wb.swt.SWTResourceManager;

import jlisp.tools.SettingTools;

import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;

public class ConsoleComposite extends Composite {
	private Label text;
	private Label text_1;
	private Label text_2;
	private Label text_3;
	private int messageNum;
	private Text text_4;

	/**
	 * Create the composite.
	 * @param parent
	 * @param style
	 */
	public ConsoleComposite(Composite parent, int style) {
		super(parent, style);
		
		this.setBounds(10, 350, 1042, 105);
		this.messageNum = 0;//初始消息数量为0
		
		
		
		text = new Label(this, SWT.NONE);
		text.setBounds(0, 0, 832, 26);
		text.setBackground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		
		text_1 = new Label(this, SWT.NONE);
		text_1.setBounds(0, 26, 832, 26);
		text_1.setBackground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		
		text_2 = new Label(this, SWT.NONE);
		text_2.setBounds(0, 52, 832, 26);
		text_2.setBackground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		
		text_3 = new Label(this, SWT.NONE);
		text_3.setBounds(0, 78, 832, 26);
		text_3.setBackground(SWTResourceManager.getColor(SWT.COLOR_BLACK));
		
		text_4 = new Text(this, SWT.BORDER | SWT.READ_ONLY | SWT.WRAP | SWT.V_SCROLL | SWT.MULTI);
		text_4.setSize(210, 104);
		text_4.setBackground(SWTResourceManager.getColor(SWT.COLOR_WHITE));
		SettingTools.setVisibleFalse(text_4);
		
		text.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseDown(MouseEvent e) {
				
				if(e.button == 1) {
					SettingTools.setVisibleTrue(text_4);
					text_4.setLocation(832, 0);
					text_4.moveAbove(null);
					//text_4.setForeground(text.getForeground());
					text_4.setText(text.getText());
				}
				if(e.button == 3) {
					
					SettingTools.setVisibleFalse(text_4);
				}
			}
		});
		text_1.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseDown(MouseEvent e) {
				if(e.button == 1) {
					SettingTools.setVisibleTrue(text_4);
					text_4.setLocation(832, 0);
					text_4.moveAbove(null);
					//text_4.setForeground(text_1.getForeground());
					text_4.setText(text_1.getText());
				}
				if(e.button == 3) {
					
					SettingTools.setVisibleFalse(text_4);
				}
			}
		});
		text_2.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseDown(MouseEvent e) {
				if(e.button == 1) {
					SettingTools.setVisibleTrue(text_4);
					text_4.setLocation(832, 0);
					text_4.moveAbove(null);
					//text_4.setForeground(text_2.getForeground());
					text_4.setText(text_2.getText());
				}
				if(e.button == 3) {
					
					SettingTools.setVisibleFalse(text_4);
				}
			}
		});
		text_3.addMouseListener(new MouseAdapter() {
			@Override
			public void mouseDown(MouseEvent e) {
				if(e.button == 1) {
					SettingTools.setVisibleTrue(text_4);
					text_4.setLocation(832, 0);
					text_4.moveAbove(null);
					//text_4.setForeground(text_3.getForeground());
					text_4.setText(text_3.getText());
				}
				if(e.button == 3) {
					
					SettingTools.setVisibleFalse(text_4);
				}
			}
		});
		
		
	}
	public void addMessage(String message, Color color) {
		switch(this.messageNum) {
			case 0:
				this.text.setForeground(color);
				this.text.setText(message);
				this.messageNum += 1;
				break;
			case 1:
				this.text_1.setForeground(color);
				this.text_1.setText(message);
				this.messageNum += 1;
				break;
			case 2:
				this.text_2.setForeground(color);
				this.text_2.setText(message);
				this.messageNum += 1;
				break;
			case 3:
				this.text_3.setForeground(color);
				this.text_3.setText(message);
				this.messageNum += 1;
				break;
			case 4:
				this.text.setForeground(text_1.getForeground());
				this.text.setText(text_1.getText());
				this.text_1.setForeground(text_2.getForeground());
				this.text_1.setText(text_2.getText());
				this.text_2.setForeground(text_3.getForeground());
				this.text_2.setText(text_3.getText());
				this.text_3.setForeground(color);
				this.text_3.setText(message);
				break;
			default:
				break;
		}
	}
	public void clearMessage() {
		this.text.setText("");
		this.text_1.setText("");
		this.text_2.setText("");
		this.text_3.setText("");
		this.messageNum = 0;
	}
	@Override
	protected void checkSubclass() {
		// Disable the check that prevents subclassing of SWT components
	}
}
